//vue3响应式

var obj = {
  name: "kkai",
  age: 18,
  others: 55555555,
};

var Pobj = new Proxy(obj, {
  get(target, key, receiver) {
    console.log(`${target[key]}被取到`);
    return target[key];
  },
  set(target, key, newValue, reciver) {
    console.log(`${target[key]}被赋值为${newValue}`);
    target[key] = newValue;
    // value = newValue;
  },

  deleteProperty(target, key) {
    console.log(`${key}被删除`);
    delete target[key];
  },

  has(target, key) {
    console.log("in操作被监听"); //in操作符:"age" in  obj"age是否存在obj之中
    return key in target;
  },
});

//读取
console.log(Pobj.name);
//改变
Pobj.age = 19;
console.log(Pobj.age);
//删除 关键字delete
delete Pobj.others;
console.log(Pobj);

//in操作
console.log("age" in Pobj);
